#!/bin/sh

if [ $# -lt 2 ]; then
    echo "\
usage: addnetwork <ssid> <password>"
    exit 1
fi

pass=$(wpa_passphrase "$1" "$2")
echo "$pass\nthis ok?"
read ANSWER
if echo $ANSWER | grep -iq "^y" ;then
    echo "$pass" | sudo tee -a /etc/wpa_supplicant/wpa_supplicant.conf
    echo "network added"
else
    echo "aborting script"
fi
